<template>
	<view class="page">
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">待入职申请</block>
			<view slot="right" class="cuIcon-more" @click="onMore"></view>
		</cu-custom>
		<view class="content">
			<view class="popup" v-show="showPopup">
				<view
				@click="menuClick(index)"
				class="popup_item"
				hover-class="l-hover"
				v-for="(item,index) in actionList"
				:key="index">
					<image class="popup_item_icon" :src="item.icon" mode=""></image>
					<view class="popup_item_label">{{item.label}}</view>
				</view>
			</view>
			<view class="search">
				<uni-search-bar
				v-model="arbitrarily"
				placeholder="请输入用户名"
				cancelText="取消"
				:radius="16"
				@confirm="onSearch"
				@input="onSearch" />
			</view>
			<view class="list">
				<ListItem v-for="(item,index) in listData" :key="item.id" :options="item"></ListItem>
				<uni-load-more v-if="!isLoadEnd || listData.length > 5" :status="loadStatus"></uni-load-more>
			</view>
		</view>
		<view class="mask" v-show="showPopup" @click.stop="showPopup = false"></view>
	</view>
</template>

<script>
	import ListItem from "./components/list-item/list-item.vue"
	export default {
		components: {
			ListItem
		},
		data() {
			return {
        arbitrarily: '',
				loadStatus: 'loading',
				isLoadEnd: false,
				listData: [],
				pageParams: {
					pageNo: 1,
					pageSize: 20
				},
				showPopup: false,
				actionList: [
					{
						icon: '/static/logo.png',
						label: '新增'
					},
					{
						icon: '/static/logo.png',
						label: '删除'
					},
					{
						icon: '/static/logo.png',
						label: '导入'
					},
					{
						icon: '/static/logo.png',
						label: '导出'
					},
					{
						icon: '/static/logo.png',
						label: '打印二维码'
					},
					{
						icon: '/static/logo.png',
						label: '修改拥有者'
					},
					{
						icon: '/static/logo.png',
						label: '批量打印'
					},
					{
						icon: '/static/logo.png',
						label: '草稿箱'
					},
				]
			};
		},
		onLoad() {
			this.getListData()
		},
		onPullDownRefresh() {
			this.pageParams.pageNo = 1
			this.getListData()
		},
		onReachBottom() {
			if(this.isLoadEnd) return
			this.pageParams.pageNo++
			this.getListData()
		},
		methods: {
			menuClick(index) {
				switch(index) {
					case 0: // 新增
						this.$Router.push({name: "crm_employment_pending_edit"})
					break;
					case 1: // 删除
					break;
					case 2: // 导入
					break;
					case 3: // 导出
					break;
					case 4: // 打印二维码
					break;
					case 5: // 修改拥有者
					break;
					case 6: // 批量打印
					break;
					case 7: // 草稿箱
					break;
				}
				this.showPopup = false
			},
			onMore() {
				this.showPopup = true
			},
			onSearch() {
				this.pageParams.pageNo = 1
				this.getListData()
			},
			getListData() {
				this.loadStatus = 'loading'
				this.$http.get("/crm_pending_employment_application/crmPendingEmploymentApplication/list",{
					params: {
						...this.pageParams,
            arbitrarily: this.arbitrarily
					}
				}).then(res => {
					if(res.data.success) {
						let list = res.data.result.records
						uni.stopPullDownRefresh()
						// 判断是否加载全部
						if(list.length < this.pageParams.pageSize) {
							this.isLoadEnd = true
							this.loadStatus = 'noMore'
						}else {
							this.loadStatus = 'more'
						}

						if(this.pageParams.pageNo === 1) {
							this.listData = list
							return
						}
						this.listData = this.listData.concat(list)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.l-hover {
		opacity: 0.5;
	}
	.page {
		background-color: #ffffff;
		min-height: 100vh;
	}
	.search {
		padding: 10rpx;
		box-sizing: border-box;
	}
	.list {
		background-color: #f5f5f5;
		min-height: calc(100vh - 210rpx);
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		padding: 30rpx;
		box-sizing: border-box;
	}
	.content {
		position: relative;
	}
	.popup {
		background-color: #ffffff;
		border-radius: 42rpx 0 42rpx 42rpx;
		padding: 54rpx;
		box-sizing: border-box;
		max-width: 550rpx;
		position: absolute;
		right: 70rpx;
		top: 30rpx;
		z-index: 10001;
		transition: all .3s;
		display: flex;
		flex-wrap: wrap;
		gap: 36rpx;
		&_item {
			width: 120rpx;
			height: 120rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			&_icon {
				width: 92rpx;
				height: 92rpx;
			}
			&_label {
				font-size: 24rpx;
				color: #000000;
				font-weight: 700;
			}
		}
	}
	.mask {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, .3);
		z-index: 10000;
		transition: all .3s;
	}
</style>
